﻿
namespace CleverCMS.Core.Infrastructure
{
    using MvcSiteMapProvider.Caching;
    using MvcSiteMapProvider.Web.Mvc;
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;

    public class AreaSiteMapCacheKeyGenerator: ISiteMapCacheKeyGenerator
    {
        public AreaSiteMapCacheKeyGenerator(IMvcContextFactory mvcContextFactory)
        {
            if (mvcContextFactory == null)
                throw new ArgumentNullException("mvcContextFactory");

            this.mvcContextFactory = mvcContextFactory;
        }

        protected readonly IMvcContextFactory mvcContextFactory;

        #region ISiteMapCacheKeyGenerator Members

        public virtual string GenerateKey()
        {
            var requestContext = this.mvcContextFactory.CreateRequestContext();
            var area = requestContext.RouteData.DataTokens["area"];
            return area == null ? "default" : area.ToString();
        }

        #endregion
    }
}